package com.gov.dna.admin.controller;


import com.gov.dna.common.util.GovStringUtils;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 页面映射
 * @author (作者) Dong Jie 154046519@qq.com
 * @version V1.0
 * @date 2019/1/6 12:07
 * @since (该版本支持的JDK版本) 1.8
 */
@Controller
@RequestMapping("/view")
@AllArgsConstructor
@Api(value="页面映射Controller",tags = {"页面映射"})
public class ViewController {

    @RequestMapping(value = "/{path}")
    public ModelAndView to(@PathVariable("path") String path, ModelAndView mv, HttpServletRequest req, HttpServletResponse res) {
        mv.setViewName(path);
        mv.addAllObjects(GovStringUtils.paramStrToMap(req.getQueryString()));
        mv.addObject("base",req.getContextPath());
        return mv;
    }

    @RequestMapping(value = "/{path}/{path2}")
    public ModelAndView to1(@PathVariable("path") String path,@PathVariable("path2") String path2, ModelAndView mv, HttpServletRequest req, HttpServletResponse res) {
        mv.setViewName(path+"/"+path2);
        mv.addAllObjects(GovStringUtils.paramStrToMap(req.getQueryString()));
        mv.addObject("base",req.getContextPath());
        return mv;
    }

    @RequestMapping(value = "/{path}/{path2}/{path3}")
    public ModelAndView to2(@PathVariable("path") String path,@PathVariable("path2") String path2,@PathVariable("path3") String path3, ModelAndView mv, HttpServletRequest req, HttpServletResponse res) {
        mv.setViewName(path+"/"+path2+"/"+path3);
        mv.addAllObjects(GovStringUtils.paramStrToMap(req.getQueryString()));
        mv.addObject("base",req.getContextPath());
        return mv;
    }
}
